Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streaming 'working' With Client-side Handling #684

Closed
wants to merge 2 commits into from
Closed

Conversation

rossdanlm
Copy link
Contributor

@rossdanlm rossdanlm commented Dec 30, 2023

Streaming 'working' With Client-side Handling

curl http://localhost:8080/api/test_streaming -d '{"prompt_name":"get_activities"}' -X POST -H 'Content-Type: application/json'

This is pretty simple, I'm expecting

  1. Create a thread to run the config.run() (t.start(): we're going to need this later so we can process the sream callback on the main thread)
  2. Do some stuff (for now don't yield, doesn't need to be anything but final version this would be the stream callback yield output contents)
  3. wait for the thread to finish executing (t.join(): by now the aiconfig output should be finalized)
  4. Yield the final aiconfig

Stack created with Sapling. Best reviewed with ReviewStack.

Rossdan Craig [email protected] added 2 commits December 29, 2023 19:41
The actual call in the `run` command will be a bit more complex since we'll have to attach a stream callback and probably create a text queue iterator like what we did for Gradio, but this shows that it's possible and shouldn't be too complicated.

Sorry Jonathan, I didn't use any of your super useful generic functions, but we can do that later.

A big thing I wanted to point out is that in the `yield` generator, I need explicitly return a string (not a json object), otherwise this will not work, so the frontend needs to be able to parse that result somehow. We should sync on this but I feel jsons are strings anyways and as long as we follow the same output "formula" (ex: in the `list_models` we out `data` key vs other commands we directly return the AIConfig json), it should be fine.
```
curl http://localhost:8080/api/test_streaming -d '{"prompt_name":"get_activities"}' -X POST -H 'Content-Type: application/json'
```

This is pretty simple, I'm expecting
1. Create a thread to run the `config.run()` (`t.start()`: we're going to need this later so we can process the sream callback on the main thread)
2. Do some stuff (for now don't yield, doesn't need to be anything but final version this would be the stream callback yield output contents)
3. wait for the thread to finish executing (`t.join()`: by now the aiconfig output should be finalized)
4. Yield the final aiconfig
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant